﻿@{
    ViewBag.Title = "【华志创】- 修改密码";
    Layout = "~/Views/Shared/___findPasswordMaster.cshtml";
}

<div class="container">
    <div class="row">
        <div class="textCon col-lg-12 col-md-8 col-sm-12">
            <div class=" textCon2 col-lg-6 col-md-8 col-sm-12">
                <p class="col-lg-6 col-md-9 col-sm-12">修改密码</p>
                <p>
                    &nbsp;&nbsp;&nbsp;新密码:
							<input type="password" name="" id="password" value="" placeholder="请设置您的新密码" />
                </p>
                <p>
                    确认密码:
							<input type="password" name="" id="repeatPassword" value="" placeholder="请在次输入您的密码" />
                </p>
                <p>
                    <button id="confirm">确认</button>
                </p>
            </div>
        </div>
    </div>
</div>

<input type="hidden" id="token" value="@(ViewBag.token)" />

@section script {
    <script type="text/ecmascript">
        $(function () {
            // 密码 & 重复密码
            var $password = $("#password");
            var $repeatPassword = $("#repeatPassword");

            // 自动检测
            $("#password,#repeatPassword").on("blur", function () {
                if (!$(this).val() || $(this).val().length < 6) {
                    $(this).addClass("faliureText").removeClass("successText");
                } else {
                    $(this).addClass("successText").removeClass("faliureText");
                }
            });

            $("#password,#repeatPassword").on("focus", function () {
                $(this).addClass("successText").removeClass("faliureText");
            })

            // 验证表单
            function validteForm() {
                $(".container input").blur();
                var isPass = true;
                $(".container input").each(function (index, item) {
                    if ($(item).hasClass("faliureText")) {
                        isPass = false;
                    }
                })

                if (!isPass) {
                    return false;
                }

                if ($repeatPassword.val() != $password.val()) {
                    showFailure("两次输入的密码不一致!");
                    return false;
                }

                return true;
            }

            // 提交密码修改
            $("#confirm").on("click", function () {

                if (validteForm()) {
                    var requestObj = {
                        token: $("#token").val(),
                        password: $("#password").val(),
                        confirmPassword: $("#repeatPassword").val()
                    }

                    $.post("/FindPassword/ChangePassword", requestObj, function (data) {
                        if (!data.status) {
                            showFailure(data.info);
                        } else {
                            showSuccess(data.info);
                            setTimeout(function () {
                                window.location.href = "/home/login";
                            }, 2000);
                        }
                    })
                } 
            })
        })

    </script>
}




